package com.bootdo.appsystem.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.appsystem.domain.OrderproductitemsDO;
import com.bootdo.appsystem.service.OrderproductitemsService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author xiaoxiao
 * @email 806191255@qq.com
 * @date 2018-05-12 14:42:14
 */
 
@Controller
@RequestMapping("/appsystem/orderproductitems")
public class OrderproductitemsController {
	@Autowired
	private OrderproductitemsService orderproductitemsService;
	
	@GetMapping()
	@RequiresPermissions("appsystem:orderproductitems:orderproductitems")
	String Orderproductitems(){
	    return "appsystem/orderproductitems/orderproductitems";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("appsystem:orderproductitems:orderproductitems")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderproductitemsDO> orderproductitemsList = orderproductitemsService.list(query);
		int total = orderproductitemsService.count(query);
		PageUtils pageUtils = new PageUtils(orderproductitemsList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("appsystem:orderproductitems:add")
	String add(){
	    return "appsystem/orderproductitems/add";
	}

	@GetMapping("/edit/{oitemid}")
	@RequiresPermissions("appsystem:orderproductitems:edit")
	String edit(@PathVariable("oitemid") Integer oitemid,Model model){
		OrderproductitemsDO orderproductitems = orderproductitemsService.get(oitemid);
		model.addAttribute("orderproductitems", orderproductitems);
	    return "appsystem/orderproductitems/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("appsystem:orderproductitems:add")
	public R save( OrderproductitemsDO orderproductitems){
		if(orderproductitemsService.save(orderproductitems)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("appsystem:orderproductitems:edit")
	public R update( OrderproductitemsDO orderproductitems){
		orderproductitemsService.update(orderproductitems);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("appsystem:orderproductitems:remove")
	public R remove( Integer oitemid){
		if(orderproductitemsService.remove(oitemid)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("appsystem:orderproductitems:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] oitemids){
		orderproductitemsService.batchRemove(oitemids);
		return R.ok();
	}
	
}
